// 这里是封装的请求工具
import type { Request } from './type' // 类型

const BASE_URL = 'http://121.89.213.194:5001'

const request = <U, T extends string | AnyObject | ArrayBuffer | undefined = undefined>({ url, method = 'GET', data }: Request<T>) => {
  return new Promise<U>((resolve, reject) => {
    uni.request({
      url: BASE_URL + url, //仅为示例，并非真实接口地址。
      method,
      data,
      success: (res) => {
        resolve(res.data as U)
      },
      fail: (error) => {
        reject(error)
      }
    });
  })
}

export default request
